<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>example03</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>example03</h1>
    <hr>
    <div id="app">
        {{num}}
        <p><button @click="add()">add</button></p>
        <!-- <p><button @click="reduce()">reduce</button></p> -->
    </div>
    <p><button onclick="reduce()">reduce</button></p>
    <p><button onclick="reduceOnce()">reduceonce</button></p>
    <p><button onclick="off()">off</button></p>
    <script type="text/javascript">
       var app = new Vue({
        el:'#app',
        data:{
            num: 1
        },
        methods:{
            add:function(){
                this.num++;
            }
        }
       });

       app.$on("reduce",function(){
        console.log("我是reduce方法");
         this.num--;
       })

       app.$once("reduceOnce",function(){
        console.log("我是reduce方法");
         this.num--;
       })

       function reduce(){
        app.$emit('reduce');
       }

       function reduceOnce(){
         app.$emit('reduceOnce');
       }

       function off(){
          app.$off('reduce');
       }
    </script>
</body>
</html>